package scau.redi.social_platform.controller.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import scau.redi.social_platform.common.staticCode.Const;
import scau.redi.social_platform.common.staticCode.ResponseCode;
import scau.redi.social_platform.common.util.ResponseUtil;
import scau.redi.social_platform.domain.pojo.UserInfo;
import scau.redi.social_platform.service.SearchService;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Author: Redi
 * @Date: 2022/5/17 21:14
 * @Description:
 */
@RestController
@Api(value = "search",description = "搜索功能")
public class SearchController {

    @Autowired
    SearchService searchService;

    @PostMapping("/searchByContent.do")
    @ApiOperation("按分享内容搜索分享（游客、普通用户、管理员）")
    public Map<String, Object> searchByContent(@RequestParam(value = "page", required = true, defaultValue = "1")Integer page,
                                               @RequestParam(value = "size", required = true, defaultValue = "5")Integer size,
                                               @RequestParam(value = "content", required = true)String content)
    {
        return ResponseUtil.success(searchService.findByContent(content, page, size));
    }

    @PostMapping("/searchUserByUsernameLike.do")
    @ApiOperation("按用户名搜索用户（游客、普通用户、管理员）")
    public Map<String, Object> searchUserByUsernameLike(@RequestParam(value = "page", required = true, defaultValue = "1")Integer page,
                                                        @RequestParam(value = "size", required = true, defaultValue = "5")Integer size,
                                                        @RequestParam(value = "content", required = true)String username)
    {
        return ResponseUtil.success(searchService.findByUsernameLike(username, page, size));
    }
}
